package com.coinworld.controller;

import com.coinworld.entity.User;
import com.coinworld.object.HttpJsonResult;
import com.coinworld.producer.SendService;
import com.coinworld.service.UserService;
import com.google.gson.Gson;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Controller
@CrossOrigin(origins = "*", maxAge = 3600)
@RequestMapping("user")
public class UserController {

    private Logger logger = LoggerFactory.getLogger(UserController.class);

    @Resource
    UserService userService;
    @Resource
    SendService SendService;


    private Gson gson = new Gson();

    @RequestMapping("/login")
    @ResponseBody
    public HttpJsonResult<User> login(HttpServletRequest request, HttpServletResponse response) {
        HttpJsonResult<User> httpJsonResult = new HttpJsonResult<User>();
//        String mobile = request.getParameter("mobile");
//        String shareId = request.getParameter("shareId");
//        String verify_code = request.getParameter("verifyCode");
//        logger.info("login request paramter:mobile" + mobile + ",shareId:" + shareId + ",verify_code:" + verify_code);
//
//        if (limiterService.tryAcquire(RATELIMTER.LIMTER_REGISTER)) {
//            if (StringUtil.isEmpty(mobile)) {
//                httpJsonResult.setSuccess(false);
//                httpJsonResult.setMsg("必填信息不能为空！");
//                return httpJsonResult;
//            }
//            if (StringUtil.isEmpty(shareId)) {
//                shareId = "kwbHxtq7";
//            }
//            if (shareId.equals("kwbHxtq7")) {
//                //首码用户
//                Integer byMobile = registerCodeDao.getByMobile(mobile);
//                if (byMobile == null || byMobile == 0) {
//                    httpJsonResult.setSuccess(false);
//                    httpJsonResult.setMsg("您不是受邀用户，不能使用该邀请码!");
//                    return httpJsonResult;
//                }
//            }
//
//            httpJsonResult = userService.login(mobile, shareId, verify_code);
//            if (httpJsonResult.getSuccess()) {
//                SendService.setRabbitMqVo(httpJsonResult.getData().getEncryptedMobile(), BUSINESS_TYPE.REGISTER, "", new BigDecimal(0), "");
//            }
//        } else {
//            httpJsonResult.setSuccess(false);
//            httpJsonResult.setMsg("当前注册人数较多，请稍后重试！");
//        }
        logger.info("login result:{}", gson.toJson(httpJsonResult));
        return httpJsonResult;
    }

}

